#include <common/config.hpp>
#include <common/logger.hpp>
#include <iostream>
#include <filesystem>

std::string get_exe_path(int argc, char** argv) {
    // 获取可执行文件的路径
    std::filesystem::path exePath = std::filesystem::absolute(std::filesystem::path(argv[0]));
    return exePath.parent_path().string(); // 返回可执行文件的目录
}

std::string get_config_path(int argc, char** argv) {
    std::string exe_path = get_exe_path(argc, argv);
    return exe_path + "/config.json";
}

int main(int argc, char** argv) {
    try {
        // 初始化日志
        Logger::init();

        std::string exe_path = get_exe_path(argc, argv);
        std::cout << "Exe path: " << exe_path << std::endl;
        
        // 获取配置实例
        std::string config_path = get_config_path(argc, argv);
        std::cout << "Config path: " << config_path << std::endl;

        Config::load_config(config_path);
        auto& config = Config::get_instance();
        
        // 打印服务器配置
        std::cout << "\n=== Server Configuration ===" << std::endl;
        std::cout << "Address: " << config.get_server_address() << std::endl;
        std::cout << "Port: " << config.get_server_port() << std::endl;
        
        // 打印MySQL配置
        std::cout << "\n=== MySQL Configuration ===" << std::endl;
        std::cout << "Host: " << config.get_mysql_host() << std::endl;
        std::cout << "Port: " << config.get_mysql_port() << std::endl;
        std::cout << "User: " << config.get_mysql_user() << std::endl;
        std::cout << "Password: " << config.get_mysql_password() << std::endl;
        std::cout << "Database: " << config.get_mysql_database() << std::endl;
        
        return 0;
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }
} 